﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BaseData_ReturnTypeEdit : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("200600107");
        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        if (Request.QueryString["code"] != null)
        {
            Label1.Text = "编辑退货原因";
            string c = Request.QueryString["code"].ToString().Trim();
            Model.RETURNTYPE l = new BLL.RETURNTYPE().GetModel(Request.QueryString["code"].ToString());
            txtCode.Text = l.RT_CODE;
            txtCode.Enabled = false;
            txtName.Text = l.RT_NAME;
            TextBox4.Text = l.RT_NOTE;
        }
    }
    protected void btnAddOrUpdate_Click(object sender, EventArgs e)
    {
        Model.RETURNTYPE l = new Model.RETURNTYPE();
        l.RT_CODE = Share.ToDBC(txtCode.Text.Trim());
        l.RT_NAME = txtName.Text.Trim();
        l.RT_NOTE = TextBox4.Text.Trim();
        if (l.RT_CODE == "" || l.RT_NAME == "")
        {
            Share.Alert(Page, "编号,名称必填！"); return;
        }
        if (Request.QueryString["code"] != null)
        {
            if (Check.CheckPermission("200600107", "00002"))
            {
                if (new BLL.RETURNTYPE().Update(l))
                {
                    Share.InsertLog("200600107", "00002");
                    Response.Redirect("ReturnType.aspx");
                }
                else
                {
                    Share.Alert(this.Page, "操作失败"); return;
                }
            }
            else
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
        }
        else
        {
            if (Check.CheckPermission("200600107", "00001"))
            {
                if (new BLL.RETURNTYPE().Exists(l.RT_CODE))
                {
                    Share.Alert(this.Page, "编号重复"); return;
                }
                else
                {
                    if (new BLL.RETURNTYPE().Add(l) != null)
                    {
                        Share.InsertLog("200600107", "00001");
                        Response.Redirect("ReturnType.aspx");
                    }
                    else
                    {
                        Share.Alert(this.Page, "操作失败"); return;
                    }
                }
            }
            else
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("ReturnType.aspx");
    }
}
